package com.liang.moshijson

import com.squareup.moshi.JsonReader


/**
 * 描述:对null数据及不匹配的类型兼容处理
 *
 * author suzl
 * createTime by 2021/6/25
 */



internal fun JsonReader.next(token: JsonReader.Token, allowTypeError: Boolean): Boolean {
    val peek = peek()
    return when {
        peek == token -> false
        peek == JsonReader.Token.NULL -> {
            nextNull<Any>()
            true
        }
        allowTypeError -> when (peek) {
            JsonReader.Token.BEGIN_ARRAY -> {
                beginArray()
                endArray()
                true
            }
            JsonReader.Token.BOOLEAN -> {
                nextBoolean()
                true
            }
            JsonReader.Token.STRING -> {
                nextString()
                true
            }
            JsonReader.Token.NUMBER -> {
                nextDouble()
                true
            }
            else -> false
        }
        else -> false
    }
}